# coding=utf-8
import time

import allure
import jsonpath

from common.assert_operator import *
from common.db import *
from common.read_yaml import *
from common.utils import Utils

string_assert = string_assert() # 字符串校验类
pact = Pact() # 契约校验类
execute_sql = sql() # sql集合
utils = Utils()
data = ReadYaml_By_Root_Dict("case/99_outside_api_test/01_workflow_outside_test/99_01_3_GetApproveStepsView_IsCanDeleteBusiness.yml").get_yaml_data()  # 读取数据

@allure.feature('测试工作流外部接口：获取审批记录、是否可删除业务数据')  # 测试报告显示测试功能
class Test_99_01_3_GetApproveStepsView_IsCanDeleteBusiness():
    """
    测试接口:
    /wf/api/ProcessEntiy/GetApproveStepsView
    /wf/api/ProcessEntiy/IsCanDeleteBusiness
    """
    # 获取yml文件中GetApproveStepsView的数据参数
    Params = data['GetApproveStepsView']
    # 获取yml的title，并作为ids的值传给用例
    ids_list = jsonpath.jsonpath(Params, "$[*][0]")
    @pytest.mark.parametrize("title, param, expect", Params, ids=ids_list)
    def test_GetApproveStepsView(self, user_login, title, param, expect):
        allure.dynamic.description(f"{param['description']}")  # # 动态解析用例描述在测试报告中展示
        main = user_login.goto_Outside_Api()    # 进入外部接口类
        user_guid = utils.get_user_guid_by_code(param['user'])    #获取用户guid
        resp = main.GetApproveStepsView(param['body'],user_guid)   #发起请求
        # 删除待办节点的历时的值，此值是动态变化的
        resp_json = resp.json()
        IPATH = jsonpath.jsonpath(resp.json(),'$.data[*].StepList[*].Nodes[*].ApproveDurationDTO.DurationDesc','IPATH')   #得到路径
        if IPATH:   #存在路径则进行删除历时值的操作
            # 通过jsonpath替换掉待办审批历时
            utils.update_json_by_jsonpath(resp_json, '$.data[*].StepList[*].Nodes[*].ApproveDurationDTO.DurationDesc',
                                          '')
            utils.update_json_by_jsonpath(expect['response'],
                                          '$.data[*].StepList[*].Nodes[*].ApproveDurationDTO.DurationDesc',
                                          '')
        dict_assert(expect['response'],resp_json)    # 结果断言

    # 获取yml文件中IsCanDeleteBusiness的数据参数
    Params = data['IsCanDeleteBusiness']
    # 获取yml的title，并作为ids的值传给用例
    ids_list = jsonpath.jsonpath(Params, "$[*][0]")
    @pytest.mark.parametrize("title, param, expect", Params, ids=ids_list)
    def test_IsCanDeleteBusiness(self, user_login, title, param, expect):
        allure.dynamic.description(f"{param['description']}")  # # 动态解析用例描述在测试报告中展示
        main = user_login.goto_Outside_Api()    # 进入外部接口类
        user_guid = utils.get_user_guid_by_code(param['user'])    #获取用户guid
        resp = main.IsCanDeleteBusiness(param['body'],user_guid)   #发起请求
        dict_assert(expect['response'],resp.json())    # 结果断言
